<template>
	<view class="content">
		<view class="input-group">
			<view class="border">
				<view style="padding-left: 15px;padding-top: 5px;" v-if="type==2">请在下面填写取消邀请缘由:</view>
				<view style="padding-left: 15px;padding-top: 5px;" v-if="type==1">请在下面填写取消预约缘由:</view>
				<view style="padding-left: 15px;padding-top: 5px;" v-if="!type">请在下面填写取消不接受邀请函缘由:</view>
				<view class="uni-textarea" style="padding-top: 5px;" v-if="type==2"><textarea auto-height v-model="yuanyou" placeholder="请填取消邀请缘由" /></view>
				<view class="uni-textarea" style="padding-top: 5px;" v-if="type==1"><textarea auto-height v-model="yuanyou" placeholder="请填取消预约缘由" /></view>
				<view class="uni-textarea" style="padding-top: 5px;" v-if="!type"><textarea auto-height v-model="yuanyou" placeholder="请填不接受邀请函缘由" /></view>
			</view>
		</view>
		<view class="btn-row"><button type="primary" class="primary" :class="{control:controlchanger}" @tap="register">提交</button></view>

		<w-picker mode="date" startYear="2017" endYear="3030" :current="false" @confirm="onConfirm" :disabledAfter="false" ref="date" themeColor="#f00"></w-picker>

		<w-picker mode="time" :current="false" :hasSecond="false" @confirm="onConfirmtime" ref="time" step="1"></w-picker>
		<!-- 底部导航 -->
		<footernav pagePath='user' v-if='shownav'></footernav>
		<!-- 加载动画 -->
		<loading v-if="!isloading()"></loading>
	</view>
</template>

<script>
import mInput from '../../components/m-input.vue';
import wPicker from '@/components/w-picker/w-picker.vue';
import request from '../../common/vmeitime-http/requstx.js';

import {appointmentrefuse} from '../../common/api/appointment.js';
let _this = null;
export default {
	components: {
		mInput,
		wPicker
	},
	data() {
		return {
			account: '',
			password: '',
			address: '',
			yuanyou: '',
			beizhu: '',
			type:'',
			choosetype:'',
			intype:'',
			refusetype:'',
			isActive: true,
			id:"",
			resultInfo: {
				result: '请选择来访日期'
			},
			resultInfotime: {
				result: '请选择来访时间'
			},
			controlchanger:false,
			showclick:true,
			skipstate:'',
			shownav:true,
		};
	},

	onShow() {},
	onLoad(event) {
		if(event.id){
			this.id=event.id;
		}
		if(event.choosetype){
			this.choosetype=event.choosetype;
		}
		if(event.type){
			this.type=event.type;
		}
		if(event.intype){
			this.intype=event.intype;
		}
		if(event.refusetype){
			this.refusetype=event.refusetype;
		}
		if(event.skipstate){
			this.skipstate=event.skipstate;
		}
		if(event.shownav=='NO'){
			this.shownav=false;
		}
		
		
		
	},
	methods: {
		toggleTab(str) {
			this.$refs[str].show();
		},
		onConfirm(val) {
			console.log(val);
			//如果页面需要调用多个mode类型，可以根据mode处理结果渲染到哪里;
			switch (this.mode) {
				case 'date':
					break;
			}
			this.resultInfo = { ...val };
			this.isActive = false;
		},
		onConfirmtime(val) {
			console.log(val);
			//如果页面需要调用多个mode类型，可以根据mode处理结果渲染到哪里;
			switch (this.mode) {
				case 'time':
					break;
			}
			this.resultInfotime = { ...val };
			this.isActive = false;
		},

		register() {
			let that=this;
			
			// if(this.controlchanger){return}
			/**
			 * 客户端对账号信息进行一些必要的校验。
			 * 实际开发中，根据业务需要进行处理，这里仅做示例。
			 */
			// uni.navigateTo({
			// 	url: '/pages/yaoqing/xiangqing'
			// });
			// return
			// if (this.resultInfo.result == '请选择来访日期') {
			// 	uni.showToast({
			// 		icon: 'none',
			// 		title: '请选择来访日期'
			// 	});
			// 	return;
			// }
			// if (this.resultInfotime.result == '请选择来访时间') {
			// 	uni.showToast({
			// 		icon: 'none',
			// 		title: '请选择来访时间'
			// 	});
			// 	return;
			// }

			// if (this.address.length == 0) {
			// 	uni.showToast({
			// 		icon: 'none',
			// 		title: '请填写来访地址'
			// 	});
			// 	return;
			// }
			
			// if (this.beizhu.length == 0) {
			// 	uni.showToast({
			// 		icon: 'none',
			// 		title: '请填写备注'
			// 	});
			// 	return;
			// }
			
			if (this.yuanyou.length == 0) {
				uni.showToast({
					icon: 'none',
					title: '请填写取消来访原因'
				});
				return;
			}
			if(this.showclick){
				this.showclick=false;
			const data = {
				account: this.account,
				password: this.password,
				email: this.email
			};
			this.visittime = this.resultInfo.result +" "+ this.resultInfotime.result;

			console.log(this.visittime);

			var datex = new Date(this.resultInfo.result);
			var time1 = datex.getTime();
			console.log(time1);
			
			var datexx = new Date(this.resultInfo.result);
			var time2 = datexx.getTime();
			console.log(time2);
			uni.showLoading({
				title: '正在进行相关操作...'  
			});
			appointmentrefuse({
				// id
				// refusereson
				// url
				
				appointmentid:this.id,
				id:this.id,
				type:this.choosetype,
				// reson:this.yuanyou,
				// Reson:this.yuanyou,
				refusereson:this.yuanyou,
				url:""
				}).then(res=>{
					uni.hideLoading(); 
					this.showclick=true;
					if(res.data.code==400){
						// uni.showToast({
						// 	icon: 'none',
						// 	title: res.data.message
						// });
						
						uni.showModal({
						    title: '',
						    content: res.data.message,						
							showCancel:false,
							confirmText: "确定",
						    success: function (res) {
						        if (res.confirm) {
						            console.log('用户点击确定');									
									
						        } else if (res.cancel) {
						            console.log('用户点击取消');
						        }
						    }
						});
						this.controlchanger = true
					}else{
						// uni.showToast({
						// 	title: res.data.message,
						// 	icon: 'none',
						// 	duration: 2000
						// });
						// uni.switchTab({
						// 	url: '/pages/main/main'
						// });
						if(that.type==1){
							var msg='您不接受本次邀请'
						}else if(that.type==2){
							var msg='您不接受本次预约'
						}else{
							var msg='您不接受本次邀请\r\n受访人将不予安排'
						}
						
						uni.showModal({
						    title: '',
						    content: msg,						
							showCancel:false,
							confirmText: "确定",
						    success: function (res) {
						        if (res.confirm) {
						            console.log('用户点击确定');
									// if(that.intype=='yq'){
									// 	uni.reLaunch({
									// 		url: "/pages/yaoqing/yaoqinglist"
									// 	});
									// }else if(that.skipstate=='c_adu'){
									// 	uni.reLaunch({
									// 		url: "/pages/comster/comster_adu"
									// 	});
									// }else{
										if(this.type==2){
											uni.reLaunch({
												url: "/pages/myyuyue/myyuyue?type=1"
											});	
										}else{
											uni.reLaunch({
												url: "/pages/myyuyue/myyuyue?type=2"
											});	
										}
											
									// }
									
						        } else if (res.cancel) {
						            console.log('用户点击取消');
						        }
						    }
						});
					}
				console.log(res)
			})
			}
		}
	}
};
</script>

<style>
.tab {
	line-height: 39px;
}
.content {
	display: flex;
	flex: 1;
	flex-direction: column;
	background-color: #efeff4;
}
.active {
	color: #747272;
}

.uni-textarea uni-textarea {
	padding-left: 3.7%;
	width: 94%;
}
.control{
	background:#5f5f5f;
}
</style>
